#include <iostream>
using namespace std;



int main() {
    string s;
    cin >> s;
    int n = s.size();
    int hash[26] = {0};
    int kind = 0;
    int l = 0,r = 0,maxlen = 0;
    while(r < n)
    {
        hash[s[r] - 'a']++;
        if(hash[s[r] - 'a'] == 1)
        {
            kind++;
        }
        while(kind > 2)
        {
            hash[s[l] - 'a']--;
            if(hash[s[l] - 'a'] == 0)
            {
                kind--;
            }
            l++;
        }
        maxlen = max(maxlen,r - l + 1);
        r++;
    }
    cout << maxlen << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")